/*
 * @Author: SeonHu
 * @Date: 2025-09-17 14:15:05
 * @LastEditors: SeonHu
 * @LastEditTime: 2025-10-24 15:40:38
 * @FilePath: \bg-vben\src\main.ts
 * @Description:
 * Copyright © 2020-2025 SANQING Corporation, All rights reserved.
 */
import { createApp } from 'vue';

// 注入全局样式
import '@vben/styles';
import '@vben/styles/antd';

import { registerGlobComp } from '@/components/registerGlobComp';
import { setupGlobDirectives } from '@/directives';
import { setupI18n } from '@/locales/setupI18n';
import { appSetup } from '@/logics/appSetup';
import { setupErrorHandle } from '@/logics/error-handle';
import { initAppConfigStore } from '@/logics/initAppConfig';
import { initPackagesConfig } from '@/logics/initPackagesConfig';
import { router, setupRouter } from '@/router';
import { setupRouterGuard } from '@/router/guard';
import { setupStore } from '@/store';

import App from './App.vue';

// 注册图标精灵
import 'virtual:svg-icons-register';

// 注入全局样式
import '@/design/index.scss';
import 'ant-design-vue/dist/reset.css';

async function bootstrap() {
  const app = createApp(App);

  // Configure store
  // 配置 store
  setupStore(app);

  // 应用设置
  await appSetup(app);

  // Initialize internal system configuration
  // 初始化内部系统配置
  initAppConfigStore();

  // Register global components
  // 注册全局组件
  registerGlobComp(app);

  // Multilingual configuration
  // 多语言配置
  // Asynchronous case: language files may be obtained from the server side
  // 异步案例：语言文件可能从服务器端获取
  await setupI18n(app);

  // Configure routing
  // 配置路由
  setupRouter(app);

  // router-guard
  // 路由守卫
  setupRouterGuard(router);

  // Register global directive
  // 注册全局指令
  setupGlobDirectives(app);

  // Configure global error handling
  // 配置全局错误处理
  setupErrorHandle(app);

  // https://next.router.vuejs.org/api/#isready
  // await router.isReady();

  // 挂载到 window
  window.$vue = app;

  // 初始化模块包配置
  initPackagesConfig(app);

  app.mount('#app');
}

bootstrap();
